#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+10;
typedef pair<int, int> PII;
typedef long long LL;
int T, n, m, V, d[N], v[N], a[N];
LL L, p[N];
PII req[N];

int lb1(LL num)
{
    int l = 1, r = m;
    while(l < r)
    {
        int mid = (l + r) >> 1;
        if(num <= p[mid]) r = mid;
        else l = mid+1;
    }
    if(l > m) return -1;
    if(r == m && num > p[r]) return -1;
    return p[r];
}

int lb(LL fz, LL fm)
{
    int l = 1, r = m;
    while(l < r)
    {
        int mid = (l + r) >> 1;
        if(fz < fm*p[mid]) r = mid;
        else l = mid+1;
    }
    if(l > m) return -1;
    if(r == m && fz >= fm*p[r]) return -1;
    return p[r];
}

int ub(LL fz, LL fm)
{
    int l = 1, r = m;
    while(l < r)
    {
        int mid = (l + r + 1) >> 1;
        if(fz < fm*p[mid]) l = mid;
        else r = mid-1;
    }
    if(l == 1 && (fz >= fm*p[l])) return -1;
    return p[l];
}

int ub1(LL fz, LL fm)
{
    int l = 1, r = m;
    while(l < r)
    {
        int mid = (l + r + 1) >> 1;
        if(fz <= fm*p[mid]) l = mid;
        else r = mid-1;
    }
    if(l == 1 && (fz > fm*p[l])) return -1;
    return p[l];
}

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> T;
    while(T--)
    {
        cin >> n >> m >> L >> V;
        for(int i = 1; i <= n; i++) cin >> d[i] >> v[i] >> a[i];
        for(int i = 1; i <= m; i++) cin >> p[i];

        //cnt cars
        int cnt = 0;
        for(int i = 1; i <= n; i++)
        {
            if(a[i] == 0)
            {
                if(d[i] <= p[m] && v[i] > V)
                {
                    ++cnt;
                    req[i] = {d[i], p[m]};
                }
                else req[i] = {-1, -1};
            }
            else if(a[i] > 0)
            {
                if(v[i] > V)
                {
                    int tmp = lb1(d[i]);
                    if(tmp >= d[i] && tmp <= p[m])
                    {
                        ++cnt;
                        req[i] = {tmp, p[m]};
                    }
                    else req[i] = {-1, -1};
                }
                else
                {
                    int tmp = lb(1ll*V*V - 1ll*v[i]*v[i] + 2ll*a[i]*d[i], a[i]*2ll);
                    if(tmp >= d[i] && tmp <= p[m])
                    {
                        ++cnt;
                        req[i] = {tmp, p[m]};
                    }
                    else req[i] = {-1, -1};
                }
            }
            else
            {
                if(v[i] < V) req[i] = {-1, -1};
                else
                {
                    int tmp = ub(1ll*V*V - 1ll*v[i]*v[i] + 2ll*a[i]*d[i], a[i]*2ll);
                    if(tmp >= d[i])
                    {
                        ++cnt;
                        req[i] = {d[i], tmp};
                    }
                    else req[i] = {-1, -1};
                }
            }
        }
        cout << cnt << ' ';

        // cnt close
        cnt = 0;
        sort(req+1, req+n+1);
        for(int i = 1, lst = 0; i <= n; i++)
        {
            if(req[i] == make_pair(-1, -1)) continue;
            int l = req[i].first, r = req[i].second;
            if(l <= lst && lst <= r) continue;
            if(lst < l) ++cnt;
            lst = ub1(-r, -1);
        }
        cout << m-cnt << '\n';

        for(int i = 1; i <= n; i++) d[i] = v[i] = a[i] = 0;
        for(int i = 1; i <= n; i++) req[i] = {0, 0};
        for(int i = 1; i <= m; i++) p[i] = 0;
    }
    return 0;
}